package com.liy.framework.common.utils;

import com.fasterxml.jackson.databind.*;
import java.util.*;
import com.fasterxml.jackson.annotation.*;

public class RequestUtil
{
    private static final ObjectMapper mapper;
    
    public static String map2urlparam(final Map<String, Object> map) {
        if (map == null) {
            return "";
        }
        final StringBuffer sb = new StringBuffer();
        for (final Map.Entry<String, Object> entry : map.entrySet()) {
            sb.append("&");
            sb.append(entry.getKey() + "=" + entry.getValue());
        }
        return sb.toString();
    }
    
    public static String vo2urlparam(final Object obj) {
        final Map<String, Object> resultMap = (Map<String, Object>)RequestUtil.mapper.convertValue(obj, (Class)Map.class);
        final StringBuffer sb = new StringBuffer();
        for (final Map.Entry<String, Object> entry : resultMap.entrySet()) {
            sb.append("&");
            sb.append(entry.getKey() + "=" + entry.getValue());
        }
        return sb.toString();
    }
    
    static {
        (mapper = new ObjectMapper()).setSerializationInclusion(JsonInclude.Include.NON_NULL);
    }
}
